
<%@page import="com.pms.platform.dto.Category"%>
<%@page import="java.text.SimpleDateFormat"%>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery/jquery.js"></script>
<script src="<%=request.getContextPath()%>/js/jquery/ui/ui.core.js" type="text/javascript" ></script>
<script src="<%=request.getContextPath()%>/js/jquery/ui/ui.datepicker.js" type="text/javascript" ></script>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/themes/base/ui.all.css">
<script src="<%=request.getContextPath()%>/js/dateutils.js" type="text/javascript" ></script>


<%
int selectedCategoryId = -1;
String strPrevMenuSel="";

	if(request.getAttribute("PrevSelMenu")!=null){
		strPrevMenuSel=(String)request.getAttribute("PrevSelMenu");
	}

	if(request.getAttribute("selectedCategoryId")!=null){
		selectedCategoryId=Integer.parseInt(request.getAttribute("selectedCategoryId").toString());
	}

   String onDate = null;
	if(request.getAttribute("ServerDate")!=null){
		onDate=(String)request.getAttribute("ServerDate");
	}
	
	Category[] category = null;
	if(request.getAttribute("categoryList")!=null){
		category = (Category[])request.getAttribute("categoryList");
	}
	
	
%>

<script language="javascript">
		
			function doDateCheck() {
				var fromTemp = document.CategoryWiseHistoryReportsForm.fromDate.value;

				var fyy = fromTemp.slice(0,4);
				var fmm = fromTemp.slice(5,7);
				var fdd = fromTemp.slice(8,10);

				var toTemp = document.CategoryWiseHistoryReportsForm.toDate.value;
				var tyy = toTemp.slice(0,4);
				var tmm = toTemp.slice(5,7);
				var tdd = toTemp.slice(8,10);
				
				var fromDate = new Date(fyy,fmm,fdd);
				var toDate = new Date(tyy,tmm,tdd);
				if (fromDate > toDate) {
					alert("To date should be greater than or equal to the From date.");
					return false;
				}

				return true;
			}

			function openReport(){
				var categoryId=document.getElementById('categoryCombo').value;
				var fromDate = document.getElementById('fromDate').value;
				var toDate = document.getElementById('toDate').value;
				var pageId = document.getElementById('pageId').value;
				var eventId = document.getElementById('eventId').value;

				if(doDateCheck() == false){
					return false;
				}

				if(document.getElementById('categoryCombo').value == -1){
					alert("please select Category.");
						return false;	
				}
					
				childwin = window.open ('ViewReport.do?pageId='+pageId+'&eventId='+eventId+'&fromDate='+fromDate+'&toDate='+toDate+'&categoryId='+categoryId, 'newwindow', config='height=' + screen.height + ',width=' +  screen.width + ', toolbar=1,left=0,top=0, menubar=1, scrollbars=1, resizable=1,location=1, directories=1, status=1');				
			}
</script>
		
<script type="text/javascript">
	$(function() {
		dpCurrServDate = yyyyMmDdToDate('<%= onDate%>');	
		$("#fromDate").datepicker({showOn: 'button',dateFormat: 'yy-mm-dd' , maxDate: '0D' , buttonImage: 'images/calender.png', buttonImageOnly: true});
		$("#toDate").datepicker({showOn: 'button',dateFormat: 'yy-mm-dd' , maxDate: '0D' , buttonImage: 'images/calender.png', buttonImageOnly: true});
	});
</script>

<form name="CategoryWiseHistoryReportsForm" method="post" action="dateSelect.do" onsubmit="return doDateCheck();">
	<input type="hidden" name="pageId" id="pageId" value='18' />
	<input type="hidden" name="eventId" id="eventId" value='3' />
 	<input type="hidden" name="PrevSelMenu" id="PrevSelMenu" value="<%=strPrevMenuSel%>"/>
	<div style="width: 500px;">
	<div id="left_side"><h3><span>&nbsp;&nbsp;Category Wise History Report</span></h3></div>
	<table  width="100%" cellpadding="2"  cellspacing="2" class="bordered_table">
	<tr>
		<td class="td_font" width="30%">From Date :</td>
		<td class="td_font" width="70%">
			<input name="fromDate" id="fromDate" type="text" readonly="readonly" size="15" value="<%=onDate %>"/> 
		</td>
	</tr>
	<tr>
		<td class="td_font" width="30%">To Date :</td>
		<td class="td_font" width="70%">
			<input name="toDate" id="toDate" type="text" readonly="readonly" size="15" value="<%=onDate %>"/>
		</td>
	</tr>
	<tr>
		<td class="td_font" width="30%">
		<div id="selectTypeLabel">Category Type :</div>
		</td>
		<td class="td_font" width="70%" align="left">
			<select id="categoryCombo" name="categoryCombo" style="width: 150px;">
				<option value='-1'> Select </option>
        			<%
               				if(category != null ){
               					for(int i = 0; i<category.length; i++ ){
               						if(selectedCategoryId == category[i].getId() ){
               			%>				
               						<option value="<%=category[i].getId() %>" selected = "selected"><%= category[i].getName() %></option>	
               					<%
               						} else{
               					%>
               						<option value="<%=category[i].getId() %>" ><%= category[i].getName() %></option>
               			<%			}
               					}
               				}
               			%>
		    </select>
		</td>
	</tr>
	<tr align="center">
		<td class="td_font" align="center" colspan="2">&nbsp;</td>
	</tr>
	<tr align="center">
		<td class="td_font" align="center" colspan="2">
		<input type="button" class="form_bttn" name="htmlReprot" value="Html Reprot" onclick="openReport();" /></td>
	</tr>
</table>
</div>
</form>
